package com.wuzheng.wisgo.sanitation.cloud.controller.picture;

import com.wuzheng.wisgo.sanitation.cloud.model.picture.PictureDTO;
import com.wuzheng.wisgo.sanitation.cloud.repository.entity.person.User;
import com.wuzheng.wisgo.sanitation.cloud.service.picture.PictureService;
import com.wuzheng.wisgo.sanitation.framework.base.annotation.Authorization;
import com.wuzheng.wisgo.sanitation.framework.base.annotation.CurrentUser;
import com.wuzheng.wisgo.sanitation.framework.base.controller.BaseController;
import com.wuzheng.wisgo.sanitation.framework.core.constant.SysRespEnum;
import com.wuzheng.wisgo.sanitation.framework.core.protocol.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @Description: 图片接口
 * @Author sunpeng
 * @Date 2019/12/10 13:16
 **/
@RestController
@RequestMapping("/picture")
@Api(value = "PictureCtrl", tags = "图片接口")
public class PictureCtrl extends BaseController {

    @Autowired
    PictureService pictureService;

    /**
     * 文件上传
     */
    @Authorization
    @ApiOperation(value = "上传文件")
    @PostMapping(value = "/upload", headers = "content-type=multipart/form-data")
    public Result<PictureDTO> uploadFile(@ApiIgnore @CurrentUser User user, @RequestBody MultipartFile file) {
        return this.success(SysRespEnum.SUCCESS.getMessage(), pictureService.upload(user, file));
    }

    /**
     * 文件删除
     */
    @ApiOperation(value = "文件删除")
    @RequestMapping(value = "/deleteByPath", method = RequestMethod.GET)
    public Result<String> deleteByPath(@RequestParam("path") String path) {
        pictureService.deleteFile(path);
        return this.success(SysRespEnum.SUCCESS.getMessage());
    }
}
